package experiment3;

public class No_8 {
    public static void main(String []args)
    {

        int[][] num= new int[][]{{4, 2}, {1, 7}, {4, 5}, {1, 2}, {1, 1}, {4, 1}};
        sort(num);
        for (int i = 0; i < num.length; i++) {
            for (int j = 0; j < num[i].length; j++) {
                System.out.print(num[i][j]);
                System.out.print(" ");
            }
            System.out.println();
        }
    }


    public static void sort(int num[][]) {
        int temp = num[0].length;
        for (int i = 0; i < temp; i++) {
            if (i == 0) //先排序第一列
                 {
                int[] temp1;//可以代表一行的所有元素
                     //保证num[i]是最小的
                for (int j = 0; j < num.length; j++) {
                    for (int j2 = j + 1; j2 < num.length; j2++) {
                        if (num[j][0] > num[j2][0]) {
                            temp1 = num[j];
                            num[j] = num[j2];
                            num[j2] = temp1;
                        }
                    }
                }
            }
            if (i == 1) //再排序第二列
            {
                int temp2;
                for (int j = 0; j < num.length; j++) {
                    for (int j2 = j + 1; j2 < num.length; j2++) {
                        if (num[j][0] == num[j2][0]) //第一列元素相同的时候
                        {
                            if (num[j][i] > num[j2][i]) {
                                temp2 = num[j][i];
                                num[j][i] = num[j2][i];
                                num[j2][i] = temp2;
                            }
                        }
                    }
                }
            }
        }

    }
}
